package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.entity.User;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.entity.User;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.qf.entity.User;
import com.qf.entity.User;
import com.qf.mapper.UserMapper;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void updateUser(User user) {
        UpdateWrapper<User> updateWrapper =new UpdateWrapper<>();
        updateWrapper.eq("id",user.getId())
                .set("username",user.getUsername())
                .set("password",user.getPassword())
                .set("real_name",user.getRealName());
        userMapper.update(null,updateWrapper);
    }

    @Override
    public void addUser(User user) {

        userMapper.insert(user);

    }

    @Override
    public void deleteUser(int id) {
        userMapper.deleteById(id);
    }

    @Override
    public IPage<User> pageFindAll(int pageNum, int pageSize) {
        IPage<User> page=new Page<>(pageNum,pageSize);
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        IPage<User> pageInfo = userMapper.selectPage(page, queryWrapper);
        return pageInfo;
    }
}
